package com.qingcloud.task.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qingcloud.task.dto.NameValueDTO;
import com.qingcloud.task.mapper.TaskFileMapper;
import com.qingcloud.task.model.TaskFile;
import com.qingcloud.task.service.TaskFileService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 勘察任务附件表 服务实现类
 * </p>
 *
 * @author zhengjibin
 * @since 2022-01-20
 */
@Service
public class TaskFileServiceImpl extends ServiceImpl<TaskFileMapper, TaskFile> implements TaskFileService {

    @Override
    public void saveFile(List<NameValueDTO> fileUrl, Integer type, Long taskId,Integer status) {
        if (CollectionUtils.isEmpty(fileUrl)){
            return;
        }
        List<TaskFile> list = new ArrayList<>(fileUrl.size());
        fileUrl.forEach(nv -> {
            TaskFile entity = new TaskFile();
            entity.setFileType(type);
            entity.setName(nv.getName());
            entity.setTaskId(taskId);
            entity.setStatus(status);
            entity.setUrl(nv.getValue());
            list.add(entity);
        });
        saveBatch(list);
    }
}
